#ifdef NOT_IN_PROJ
//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#include <QListWidgetItem>
#include <model/particletemplate.h>
#include <model/root.h>
#include "fwlistview.h"
#include "docevent.h"
#include "docevents.h"
#include "viewattributes.h"
using namespace model;
//
class PTListItem : public QListWidgetItem {
public:
   PTListItem(ParticleTemplate *p_pt, QListWidget *parent = 0);
   ParticleTemplate *get_pt() const {return pt;}
private:
   ParticleTemplate *pt;
};
PTListItem::PTListItem(model::ParticleTemplate *p_pt, QListWidget *parent)
:
QListWidgetItem(p_pt->get_name(), parent), pt(p_pt)
{
}
//
FwListView::FwListView(QWidget *parent) : QWidget(parent), is_invalid(false) {
   ui.setupUi(this);
   connect(ui.particle_templates, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), SLOT(curPTChanged(QListWidgetItem*, QListWidgetItem*)));
   handle_set_attr_group();
}
FwListView::~FwListView() {
}
void FwListView::delete_all() {
   ui.emitter_templates->clear();
   ui.particle_templates->clear();
}
void FwListView::populate_all() {
   if (get_document() == NULL)
      return;
   Root *root = get_document()->get_root();
   QSet<ParticleTemplate*>::const_iterator i = root->particle_templates.begin();
   while (i != root->particle_templates.end()) {
      new PTListItem(*i, ui.particle_templates);
      ++i;
   }
}
void FwListView::handle_set_attr_group() {
   if (get_document() != 0) {
      delete_all();
      populate_all();
      setEnabled(true);
   } else {
      delete_all();
      setEnabled(false);
   }
}
void FwListView::curPTChanged(QListWidgetItem *current, QListWidgetItem *previous) {
   PTListItem *curr = static_cast<PTListItem*>(current);
   if (get_attr_group()) {
      if (curr)
         ViewAttributeType::ParticleTemplate::lookup(get_attr_group(), selected_particle_template)->set_pt(curr->get_pt(), this);
      else
         ViewAttributeType::ParticleTemplate::lookup(get_attr_group(), selected_particle_template)->set_pt(NULL, this);
   }
}
void FwListView::handle_doc_event(DocEvent* event) {
   switch (event->type) {
   case DocEvent::something:
      delete_all();
      populate_all();
      break;
   //case new_particle_template: {
      //DocEvents::NewParticleTemplate *ev = static_cast<DocEvents::NewParticleTemplate*>(event);
      //..
      //break;
   //}
   default:
      delete_all();
      populate_all();
   }
}
#endif
